package schoolWork.work02;

public class Voter {
    String name;
    static String[] candidates={"ZhangSan","LiSi","WangWu"};
    static int[] polls={0,0,0};

    //构造方法
    //传入姓名
    public Voter(String name){
        this.name = name;
    }
    //统计得票
    public boolean voteFor(String name){
        boolean flag = false;
        for (int i = 0; i < candidates.length; i++) {
           if(name.equalsIgnoreCase(candidates[i])){
               polls[i]++;
               flag = true;
               break;
           }
        }
        return flag;
    }
    //找出票数最多者下标
    public static int findMaxIndex(){
        int indexMax = 0;
        for (int i = 1; i < candidates.length; i++) {
            if(polls[i]>=polls[indexMax])
            {
                indexMax = i;
            }
        }
        return indexMax;
    }
}
